package com.example.demo.common;

import com.example.demo.entity.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author：徐志荣
 * @Date：2023/6/29 上午 10:10
 */

//当前登录用户相关的操作
public class UserSessionUtils {

    //得到当前的登录用户
    public static Userinfo getUser(HttpServletRequest request){
        //有就拿,没有也不创建
        HttpSession session = request.getSession(false);
        if(session != null && session.getAttribute(AppVariable.USER_SESSION_KEY) != null){
            return (Userinfo) session.getAttribute(AppVariable.USER_SESSION_KEY);
        }

        return  null;
    }

}
